package me.yushuai.wukong.base.entity;

import lombok.Data;
import lombok.EqualsAndHashCode;
import me.yushuai.wukong.common.domain.AbstractAudit;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 批次定义用于定义批次规则，不同物品可以使用对应规则来存储属性信息
 *
 * @author zhoushuai@189.cn
 * @since 2023-03-01
 */
@Entity
@Table(name = "BAS_LOT_DEF")
public class LotDef extends AbstractAudit {

    @Id
    @Column(name = "ID")
    private Long id;

    @Column(name = "TITLE", nullable = false, length = 40)
    private String title;

    @Column(name = "NOTES", length = 200)
    private String notes;

    @Transient
    private List<LotAttrDef> lotAttrDefs = new ArrayList<>();

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getNotes() {
        return notes;
    }

    public void setNotes(String notes) {
        this.notes = notes;
    }

    public List<LotAttrDef> getLotAttrDefs() {
        return lotAttrDefs;
    }

    public void setLotAttrDefs(List<LotAttrDef> lotAttrDefs) {
        this.lotAttrDefs = lotAttrDefs;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        if (!super.equals(o)) {
            return false;
        }
        LotDef lotDef = (LotDef) o;
        return getId().equals(lotDef.getId()) && Objects.equals(getTitle(), lotDef.getTitle()) && Objects.equals(getNotes(), lotDef.getNotes()) && Objects.equals(getLotAttrDefs(), lotDef.getLotAttrDefs());
    }

    @Override
    public int hashCode() {
        return Objects.hash(super.hashCode(), getId(), getTitle(), getNotes(), getLotAttrDefs());
    }

    @Override
    public String toString() {
        return "LotDef{" +
                "id=" + id +
                ", title='" + title + '\'' +
                ", notes='" + notes + '\'' +
                ", lotAttrDefs=" + lotAttrDefs +
                '}';
    }
}
